<script lang="ts" setup>
/*
  学习目标：掌握defineEmits的TS写法
*/

interface Props {
  money: number;
  car?: string;
  gender?: string;
}

const { car = "梅赛德斯", gender = "男" } = defineProps<Props>()


// 1. ✅定义函数签名类型
interface Emits {
  (name: 'changeMoney', count: number): void;
  (name: 'changeCar', car: string): void;
}

// 2. 泛型函数完整写法
const emit = defineEmits<Emits>()


// 💥 注意TS中defineEmits不需要传参数
// ❌ const emit = defineEmits<Emits>(["changeMoney", "changeCar"])
</script>

<template>
  <div>{{ money }} - {{ car }} - {{ gender }}</div>
  <button @click="emit('changeMoney', 2)">点我</button>
</template>
